﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Client
{
    public partial class Chat : Form
    {
        public Connection currConn;
        string _UserName;
        string color;

        public string getName
        {
            get
            {
                return _UserName;
            }
        }

       

        string[] names; int i = 0;

        public List<Private> listPrivates = new List<Private>();
        public Chat(Connection _conn,string _UserName, string _Color)
        {
            color = _Color;
            InitializeComponent();
            themes(color);
            this._UserName = _UserName;
            currConn = _conn;
        }
        /// <summary>
        /// Add this user to ListBox1.Items.
        /// </summary>
        /// <param name="name">The user added</param>
        public void listBox1_Name(string name)
        {
            listBox1.Items.Add(name);
            //Private priv = new Private(currConn, _UserName, name);
            //listPrivates.Add(priv);

        }
        /// <summary>
        /// Remove user from ListBox1.Items, if user logouts
        /// </summary>
        /// <param name="_removeUser">The user removed</param>
        public void removeUser(string _removeUser)
        {
            
             for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    if (String.Compare(listBox1.GetItemText(listBox1.Items[i]),_removeUser)==0)
                    {
                        listBox1.Items.RemoveAt(i);
                    }
                }
           
        }
        //logout
        private void button2_Click(object sender, EventArgs e)
        {
            currConn.sendtoServ("disconnect", "");
            Chat.ActiveForm.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            currConn.sendtoServ("message",_UserName+": "+textBox1.Text);
            textBox1.Text = "";
            textBox1.Focus(); 
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                currConn.sendtoServ("message", _UserName + ": " + textBox1.Text);
                textBox1.Text = "";
                textBox1.Focus();                   
            }
        }
        
        public void message(string msg)
        {
            textBox2.Text += (msg+"\r\n");
            textBox2.SelectionStart = textBox2.Text.Length;
            textBox2.ScrollToCaret();
            textBox2.Refresh();
        }

        //TextBox text;

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e) 
        {

            //currConn.sendtoServ("roomlistUser", listBox1.GetItemText(listBox1.SelectedItem));
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            textBox2.Text = "";
            listBox1.Items.Clear();
            currConn.sendtoServ("changeroom", listBox2.SelectedIndex.ToString());
            textBox1.Focus();

        }
        

        public void addroom(string roomname)
        {
            
            listBox2.Items.Add(roomname);
        }

        public void themes(string _color)
        {
            if (_color == "blue")
            {
                //BG
                this.BackgroundImage = Image.FromFile("blueBG.jpg");

                //rooms
                this.label1.Font = new System.Drawing.Font("Papyrus", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.label1.ForeColor = System.Drawing.Color.LightSlateGray;

                this.listBox2.BackColor = System.Drawing.Color.LightSlateGray;
                this.listBox2.Font = new System.Drawing.Font("Papyrus", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.listBox2.ForeColor = System.Drawing.Color.White;

                //userlist
                this.label2.Font = new System.Drawing.Font("Papyrus", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.label2.ForeColor = System.Drawing.Color.LightSlateGray;

                this.listBox1.BackColor = System.Drawing.Color.LightSlateGray;
                this.listBox1.Font = new System.Drawing.Font("Papyrus", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.listBox1.ForeColor = System.Drawing.Color.White;

                //textbox2
                this.textBox2.BackColor = System.Drawing.Color.LightSlateGray;
                this.textBox2.Font = new System.Drawing.Font("Papyrus", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                //textBox1
                this.textBox1.BackColor = System.Drawing.Color.LightSlateGray;
                this.textBox1.Font = new System.Drawing.Font("Papyrus", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                //sendButton
                this.button1.BackColor = System.Drawing.Color.LightSlateGray;
                this.button1.Font = new System.Drawing.Font("Papyrus", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.button1.ForeColor = System.Drawing.Color.Black;

                //logoutButton
                this.button2.BackColor = System.Drawing.Color.LightSlateGray;
                this.button2.Font = new System.Drawing.Font("Papyrus", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.button2.ForeColor = System.Drawing.Color.Black;
            }

            if (_color == "green")
            {
                //BG
                this.BackgroundImage = Image.FromFile("greenBG.jpg");

                //rooms
                this.label1.Font = new System.Drawing.Font("Broadway", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.label1.ForeColor = System.Drawing.Color.DarkKhaki;

                this.listBox2.BackColor = System.Drawing.Color.DarkKhaki;
                this.listBox2.Font = new System.Drawing.Font("Broadway", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.listBox2.ForeColor = System.Drawing.Color.Black;

                //userlist
                this.label2.Font = new System.Drawing.Font("Broadway", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.label2.ForeColor = System.Drawing.Color.DarkKhaki;

                this.listBox1.BackColor = System.Drawing.Color.DarkKhaki;
                this.listBox1.Font = new System.Drawing.Font("Broadway", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.listBox1.ForeColor = System.Drawing.Color.Black;

                //textbox2
                this.textBox2.BackColor = System.Drawing.Color.DarkKhaki;
                this.textBox2.Font = new System.Drawing.Font("Broadway", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                //textBox1
                this.textBox1.BackColor = System.Drawing.Color.DarkKhaki;
                this.textBox1.Font = new System.Drawing.Font("Broadway", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                //sendButton
                this.button1.BackColor = System.Drawing.Color.DarkKhaki;
                this.button1.Font = new System.Drawing.Font("Broadway", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.button1.ForeColor = System.Drawing.Color.Black;

                //logoutButton
                this.button2.BackColor = System.Drawing.Color.DarkKhaki;
                this.button2.Font = new System.Drawing.Font("Broadway", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.button2.ForeColor = System.Drawing.Color.Black;
            }

            if (_color == "red")
            {
                //BG
                this.BackgroundImage = Image.FromFile("redBG.jpg");

                //rooms
                this.label1.Font = new System.Drawing.Font("Century Gothic", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.label1.ForeColor = System.Drawing.Color.LightSalmon;

                this.listBox2.BackColor = System.Drawing.Color.LightSalmon;
                this.listBox2.Font = new System.Drawing.Font("Century Gothic", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.listBox2.ForeColor = System.Drawing.Color.Black;

                //userlist
                this.label2.Font = new System.Drawing.Font("Century Gothic", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.label2.ForeColor = System.Drawing.Color.LightSalmon;

                this.listBox1.BackColor = System.Drawing.Color.LightSalmon;
                this.listBox1.Font = new System.Drawing.Font("Century Gothic", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.listBox1.ForeColor = System.Drawing.Color.Black;

                //textbox2
                this.textBox2.BackColor = System.Drawing.Color.LightSalmon;
                this.textBox2.Font = new System.Drawing.Font("Century Gothic", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                //textBox1
                this.textBox1.BackColor = System.Drawing.Color.LightSalmon;
                this.textBox1.Font = new System.Drawing.Font("Century Gothic", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));

                //sendButton
                this.button1.BackColor = System.Drawing.Color.LightSalmon;
                this.button1.Font = new System.Drawing.Font("Century Gothic", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.button1.ForeColor = System.Drawing.Color.White;

                //logoutButton
                this.button2.BackColor = System.Drawing.Color.LightSalmon;
                this.button2.Font = new System.Drawing.Font("Century Gothic", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.button2.ForeColor = System.Drawing.Color.White;
            }

            if (_color == "purple")
            {
                //BG
                this.BackgroundImage = Image.FromFile("purpleBG.jpg");

                //rooms
                this.label1.Font = new System.Drawing.Font("Kristen ITC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.label1.ForeColor = System.Drawing.Color.White;

                this.listBox2.BackColor = System.Drawing.Color.Plum;
                this.listBox2.Font = new System.Drawing.Font("Kristen ITC", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.listBox2.ForeColor = System.Drawing.Color.Black;

                //userlist
                this.label2.Font = new System.Drawing.Font("Kristen ITC", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.label2.ForeColor = System.Drawing.Color.White;

                this.listBox1.BackColor = System.Drawing.Color.Plum;
                this.listBox1.Font = new System.Drawing.Font("Kristen ITC", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.listBox1.ForeColor = System.Drawing.Color.Black;

                //textbox2
                this.textBox2.BackColor = System.Drawing.Color.Plum;
                this.textBox2.Font = new System.Drawing.Font("Kristen ITC", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                //textBox1
                this.textBox1.BackColor = System.Drawing.Color.Plum;
                this.textBox1.Font = new System.Drawing.Font("Kristen ITC", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                //sendButton
                this.button1.BackColor = System.Drawing.Color.Plum;
                this.button1.Font = new System.Drawing.Font("Kristen ITC", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.button1.ForeColor = System.Drawing.Color.Black;

                //logoutButton
                this.button2.BackColor = System.Drawing.Color.Plum;
                this.button2.Font = new System.Drawing.Font("Kristen ITC", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.button2.ForeColor = System.Drawing.Color.Black;
            }
        }

    }
}
